﻿using System;
using System.Collections.Generic;
using System.Windows;

namespace System
{
    /// <summary>
    /// 错误码帮助类
    /// </summary>
    public static class ErrorHelper
    {
        private static readonly Dictionary<int, string> ErrorDic;

        private static ResourceDictionary _errorDic;
        static ErrorHelper()
        {
            _errorDic = new ResourceDictionary();
            _errorDic.Source = new Uri("pack://application:,,,/Base.Common;component/Helper/ErrorHelper/zh-CN_ErrorCode.xaml", UriKind.RelativeOrAbsolute);

            #region  给ErrorDic进行赋值
            ErrorDic = new Dictionary<int, string>
            {
                {0, (string)_errorDic["ErrorCode0"]},
            };

            #endregion 给ErrorDic进行赋值
        }

        /// <summary>
        /// 获取错误码对应内容
        /// </summary>
        /// <param name="num">error code</param>
        /// <returns>Error description information</returns>
        public static string GetError(int num)
        {
            string errorMessage;
            ErrorDic.TryGetValue(num, out errorMessage);
            if (errorMessage == null)
                errorMessage = (string)_errorDic["ErrorCode-1"];

            return errorMessage + "(" + num + ")";
        }
    }
}